home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / message / subcls / leftcap.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-31  |  3.1 KB  |  93 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Left-Aligned Caption"
  4.    ClientHeight    =   3330
  5.    ClientLeft      =   1080
  6.    ClientTop       =   1515
  7.    ClientWidth     =   6420
  8.    Height          =   3735
  9.    Left            =   1020
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3330
  12.    ScaleWidth      =   6420
  13.    Top             =   1170
  14.    Width           =   6540
  15.    Begin MsgHook MsgHook 
  16.       Left            =   135
  17.       Top             =   180
  18.    End
  19.    Begin Timer Timer1 
  20.       Interval        =   1000
  21.       Left            =   810
  22.       Top             =   180
  23.    End
  24. Option Explicit
  25. ' Routine within MsgHook which calls default window procedure
  26. Declare Function InvokeWindowProc Lib "MsgHook.vbx" (ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Long
  27. ' We want to catch messages causing non-client repaints
  28. Const WM_NCPAINT = &H85
  29. Const WM_NCACTIVATE = &H86
  30. Const WM_SIZE = &H5
  31. ' Store Caption as a string
  32. Dim Kaption As String
  33. Sub Form_Load ()
  34.    ' Set Caption to "", storing whatever was set at design
  35.    Kaption = Me.Caption
  36.    Me.Caption = ""
  37.    ' Setup MsgHook control
  38.    MsgHook.HwndHook = Me.hWnd
  39.    MsgHook.Message(WM_NCPAINT) = True
  40.    MsgHook.Message(WM_NCACTIVATE) = True
  41.    MsgHook.Message(WM_SIZE) = True
  42. End Sub
  43. Sub MsgHook_Message (Msg As Integer, wParam As Integer, lParam As Long, Result As Long)
  44.    Static PrevState As Integer
  45.    ' Fire default window procedure before processing
  46.    ' any of the messages we're interested in for this
  47.    ' task.
  48.    Result = InvokeWindowProc(MsgHook.HwndHook, Msg, wParam, lParam)
  49.    ' Check which message arrived, and act accordingly.
  50.    Select Case Msg
  51.       Case WM_NCPAINT
  52.          '
  53.          ' Check whether to paint as active or inactive
  54.          '
  55.          RefreshCaption Kaption, Me, (GetActiveWindow() = Me.hWnd)
  56.       Case WM_NCACTIVATE
  57.          '
  58.          ' wParam indicates active or inactive
  59.          '
  60.          RefreshCaption Kaption, Me, wParam
  61.       Case WM_SIZE
  62.          '
  63.          ' Supply Caption for minimized icon only
  64.          '
  65.          If wParam = SIZE_MINIMIZED Then 'Minimized
  66.             Me.Caption = Kaption
  67.          ElseIf PrevState = SIZE_MINIMIZED Then
  68.             Kaption = Me.Caption
  69.             Me.Caption = ""
  70.             RefreshCaption Kaption, Me, True
  71.          End If
  72.          '
  73.          ' Store "last" WindowState
  74.          '
  75.          PrevState = Me.WindowState
  76.    End Select
  77. End Sub
  78. Sub Timer1_Timer ()
  79.    Dim TmpCaption As String
  80.    ' Adorn visible caption with extra text
  81.    TmpCaption = Kaption & " -- " & Format$(Now, "h:mm:ssam/pm")
  82.    RefreshCaption TmpCaption, Me, (GetActiveWindow() = Me.hWnd)
  83. End Sub
  84. Sub UpdateCaption (NewCaption$)
  85.    ' Provide an easy means to update the Caption at will.
  86.    Kaption = NewCaption
  87.    If Me.WindowState = SIZE_MINIMIZED Then
  88.       Me.Caption = NewCaption
  89.    Else
  90.       RefreshCaption Kaption, Me, (GetActiveWindow() = Me.hWnd)
  91.    End If
  92. End Sub
  93.